/*
//  Copyright © 2014 Allen County Public Library.

  //        ACPL Mobile is free software: This program is distributed and you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.  ACPL Mobile is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY, including without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with ACPL Mobile. If not, see http://www.gnu.org/licenses/.
 * Author: James Harpe
 * 
 * 
 * Description: This is the main menu for the app. 
 */

package us.in.lib.acpl.Mobile_ACPL;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.google.analytics.tracking.android.EasyTracker;
import us.in.lib.acpl.Mobile_ACPL.adapters.MainListAdapter;
import us.in.lib.acpl.Mobile_ACPL.parents.BaseListActivity;

public class Mobile_ACPLActivity extends BaseListActivity {
	/** Called when the activity is first created. */

	@Override
	public void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.main);
		this.setListAdapter(new MainListAdapter(this, this.getResources()
				.getStringArray(R.array.options)));
		ListView lv = this.getListView();

		// Set up listener for the buttons.
		lv.setOnItemClickListener(new OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				
				System.out.println("click");
				RelativeLayout rl = (RelativeLayout) view;
				TextView t = (TextView) rl.findViewById(R.id.mainListText);
				System.out.println(t.getText());
				if (position==1) {
					System.out.println("Search Catalog pressed");
					Intent intent = new Intent(parent.getContext(),
							SearchActivity.class);
					startActivity(intent);

				}
				if (position==6) {
					Intent intent = new Intent(parent.getContext(),
							LocationActivity.class);
					startActivity(intent);
				}
				if (position==2) {

					SharedPreferences prefs = getSharedPreferences("myPrefs",
							Context.MODE_WORLD_WRITEABLE);
					boolean loggedIn = prefs.getBoolean("loggedIn", false);

					if (loggedIn) {
						Intent intent = new Intent(parent.getContext(),
								AccountActivity.class);
						startActivity(intent);
					} else {

						Intent intent = new Intent(parent.getContext(),
								LoginActivity.class);
						intent.putExtra("destination", "myAccount");
						startActivity(intent);
					}

				}
				if(position==3){

					SharedPreferences prefs = getSharedPreferences("myPrefs",
							Context.MODE_WORLD_WRITEABLE);
					boolean loggedIn = prefs.getBoolean("loggedIn", false);

					if (loggedIn) {
						Intent intent = new Intent(parent.getContext(),
								OverdriveActivity_.class);
						startActivity(intent);
					} else {

						Intent intent = new Intent(parent.getContext(),
								LoginActivity.class);
						intent.putExtra("destination", "overdrive");
						startActivity(intent);
					}
				}
				if (position==8) {
				
						Intent intent = new Intent(parent.getContext(),
								SettingsActivity.class);
						startActivity(intent);
				

				}

				if (position==7) {

					SharedPreferences prefs = getSharedPreferences("myPrefs",
							Context.MODE_WORLD_WRITEABLE);
					boolean loggedIn = prefs.getBoolean("loggedIn", false);

					if (loggedIn) {

						String data = prefs.getString("user", null);
						data = "A" + data + "T";
						//data = "A21833009999999T";
						Intent intent = new Intent(
								"com.google.zxing.client.android.ENCODE");

						intent.putExtra("ENCODE_FORMAT", "CODABAR");

						intent.putExtra("ENCODE_DATA", data);

						startActivity(intent);
					} else {
						Intent intent = new Intent(parent.getContext(),
								LoginActivity.class);
						intent.putExtra("destination", "displayBarcode");
						startActivity(intent);
					}

				}
				if (position==5) {
					Intent intent = new Intent(parent.getContext(),
							EventMainActivity.class);
					startActivity(intent);
				}
				if (position==0){
					Intent intent = new Intent(parent.getContext(),FeaturedTitlesActivity_.class);
					startActivity(intent); 
				}
				if(position==4){
					Intent intent = new Intent(parent.getContext(),MyListsActivity_.class);
					startActivity(intent);
				}
			}
		});

	}
	  @Override
	  public void onStart() {
	    super.onStart();
	    EasyTracker.getInstance().activityStart(this); // Add this method.
	  }

	  @Override
	  public void onStop() {
	    super.onStop();
	    EasyTracker.getInstance().activityStop(this); // Add this method.
	  }
	


}